package net.adetech.crj.web;

import net.adetech.crj.entity.Advice;
import net.adetech.crj.entity.User;
import net.adetech.crj.utils.ServiceUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
public class AdviceWebController {

    @Autowired
    ServiceUtil serviceUtil;

    @RequestMapping(value = "/advice/page/add")
    public String addNewAdvicePage()
    {
        return "addAdvice";
    }

    @RequestMapping(value = "/advice/page/result")
    public String adviceResultPage(String content,HttpSession session)
    {
        User user = (User)session.getAttribute("currentUser");
        Advice advice = new Advice();
        advice.setAdviceContent(content);
        advice.setUserIdNumber(user.getIdNumber());
        advice.setPhoneNumber(user.getPhoneNumber());
        serviceUtil.callService("advice.new","advice",advice);
        return "adviceResult";
    }
}
